package com.example.service;

import cn.hutool.core.util.ObjectUtil;
import com.example.common.Constants;
import com.example.common.Result;
import com.example.enums.ResultCodeEnum;
import com.example.exception.CustomException;
import com.example.mapper.RegisterMapper;
import com.example.pojo.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterService {

    @Autowired
    private RegisterMapper registerMapper;

    public void add(Emp emp) {
       Emp e = registerMapper.selectByUsername(emp.getUsername());
        if(ObjectUtil.isNull(e)){
            emp.setPassword(Constants.ADMIN_USER_PASSWORD);
            emp.setName(emp.getUsername());
            emp.setImage(Constants.ADMIN_USER_IMAGE);
            registerMapper.insert(emp);

        }else{
            throw new CustomException(ResultCodeEnum.USER_EXIST_ERROR);
        }

    }
}
